import 'core-js/es6/promise';
import axios from 'axios';
import Vue from 'vue';
import VRouter from 'vue-router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '../../../static/css/common.css';
import {mytips} from '@/module/tools';

Vue.use(ElementUI);
Vue.use(VRouter);

const login = resolve => require(['@/component/login.vue'], resolve);
const basic = resolve => require(['@/component/basic.vue'], resolve);
/*center部分的组件*/
const customerList = resolve => require(['./customer/customerList.vue'], resolve);
const realNameList = resolve => require(['./customer/realNameList.vue'], resolve);
const uploadPic = resolve => require(['./customer/uploadPic.vue'], resolve);
const channelList = resolve => require(['./channel/channelList.vue'], resolve);
const flowPoolList = resolve => require(['./channel/flowPool.vue'], resolve);
const cardStatistic = resolve => require(['./dataStatistic/cardStatistic.vue'], resolve);
const cardList = resolve => require(['./card/cardList.vue'], resolve);
const inputRecordList = resolve => require(['./card/inputRecordList.vue'], resolve);
const outputRecordList = resolve => require(['./card/outputRecordList.vue'], resolve);
const batchOperateList = resolve => require(['./card/batchOperateList.vue'], resolve);
const specialOperateList = resolve => require(['./card/specialOperateList.vue'], resolve);
const comboList = resolve => require(['./combo/comboList.vue'], resolve);
const rateList = resolve => require(['./combo/rateList.vue'], resolve);
const platformStreamList = resolve => require(['./assets/platformStreamList.vue'], resolve);
const customerStreamList = resolve => require(['./assets/customerStreamList.vue'], resolve);
const roleList = resolve => require(['./system/roleList.vue'], resolve);
const accountList = resolve => require(['./system/accountList.vue'], resolve);
const resourceList = resolve => require(['./system/resourceList.vue'], resolve);
const logList = resolve => require(['./system/logList.vue'], resolve);
const orderList = resolve => require(['./order/orderList.vue'], resolve);
const index = resolve => require(['./index/index.vue'], resolve);

Vue.config.productionTip = false;

const router = new VRouter({
    routes: [
        {path: '*', redirect: '/realNameList'},
        {name: 'basic', path: '/basic', component: basic},
        {name: 'login', path: '/login', component: login},
        {name: 'customerList', path: '/customerList', component: customerList},
        {name: 'realNameList', path: '/realNameList', component: realNameList},
        {name: 'uploadPic', path: '/uploadPic', component: uploadPic},
        {name: 'channelList', path: '/channelList', component: channelList},
        {name: 'flowPoolList', path: '/flowPoolList', component: flowPoolList},
        {name: 'cardStatistic', path: '/cardStatistic', component: cardStatistic},
        /*套餐管理*/
        {name: 'comboList', path: '/comboList', component: comboList},
        {name: 'rateList', path: '/rateList', component: rateList},
        /*卡管理*/
        {name: 'cardList', path: '/cardList', component: cardList},
        {name: 'inputRecordList', path: '/inputRecordList', component: inputRecordList},
        {name: 'outputRecordList', path: '/outputRecordList', component: outputRecordList},
        {name: 'batchOperateList', path: '/batchOperateList', component: batchOperateList},
        {name: 'specialOperateList', path: '/specialOperateList', component: specialOperateList},
        /*资产管理*/
        {name: 'platformStreamList', path: '/platformStreamList', component: platformStreamList},
        {name: 'customerStreamList', path: '/customerStreamList', component: customerStreamList},
        /*系统管理*/
        {name: 'roleList', path: '/roleList', component: roleList},
        {name: 'accountList', path: '/accountList', component: accountList},
        {name: 'resourceList', path: '/resourceList', component: resourceList},
        {name: 'logList', path: '/logList', component: logList},
        /*登录首页*/
        {name: 'index', path: '/index', component: index},
        /*订单管理*/
        {name: 'orderList', path: '/orderList', component: orderList},
    ],
});
//响应拦截器
axios.interceptors.response.use(
    res => {
        window.mytips = mytips;
        if (res.data.code == 405) {
            window.location.href = "/index.html"
        } else if (res.data.code > 0) {
            console.log("返回的响应code>0");
            mytips(res.data.message);
            // window.location.href="/index.html";
            window.location.href = "/center.html#/cardList";
        } else if (res.data.code < 0) {
            console.log("返回的响应code<0")
            mytips('系统异常')
        }
        return res;
    },
    error => {
        mytips('连接异常');
        return Promise.reject(error);
    }
);

var app = new Vue({
    el: '#app',
    router,
    data() {
        return {
            restNum: 1,
            username: '涛涛',
            nav: ['login', 'basic'],
        }
    },
    methods: {
        handleSelect(key, keyPath) {
            //控制导航页的页面跳转
            console.log("控制导航页的页面跳转")
            this.$router.push(keyPath);
            // console.log(key, keyPath);
        },
        skip(a) {
            console.log(a);
            this.$router.push(a)
        },
        getUser() {
            axios({
                url: API_PATH + '/user'
            }).then(res => {
                if (res.data.code == 0) {
                    console.log(res);
                    this.username = res.data.data.username
                }
            })
        },
        hasPerm(perm) {
            return this.nav.indexOf(perm) > -1 ? true : false;
        },
        handleCommand(command) {
            if (command == 'index') {
                console.log("点击子菜单", command);
                this.$router.push("/index");
            } else if (command == 'logout') {
                window.location.href = "/index.html";
            } else if (command == 'realName') {
                this.$router.push("/basic")
            }
        },
    },
    watch: {
        $route(to, from) {
            console.log("to========");
            console.log(to);
            console.log(from);
            console.log('this.$router', this.$router);
            console.log('this.$route', this.$route);
        }
    },
    computed: {
        activeNav: function () {
            // return this.$router.current.fullPath
           // console.log('改变前', this.activeNav);
            return this.$route.path;
        }
    }
})
